home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / gateway.idb / usr / WebFace / Tasks / dhcp-end.cgi.z / dhcp-end.cgi
Encoding:
Text File  |  1997-07-30  |  6.9 KB  |  236 lines

  1. #!/usr/bin/perl5
  2. #
  3. # dhcp-end.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: dhcp-end.cgi,v 1.14 1997/06/24 22:20:56 shotes Exp $
  21.  
  22. require "/usr/OnRamp/lib/OnRamp.pm";
  23.  
  24. if (!$ARGV[0]) { printf("Location: %s%c%c","/tasks/Tasks.dhcp-start.cgi",10,10); } 
  25.  
  26. $myname = "dhcp-end.cgi?" . $ARGV[0];
  27. $def_config_dir = "/var/dhcp/config";
  28. $inetd_conf = "/etc/inetd.conf";
  29. $temp = "task.tmp";
  30. $dummy = "task.dummy";
  31.  
  32. $it = "<td colspan=60>";
  33. $ni = "</td>";
  34. $bo = "<td colspan=150><font size=5><i>";
  35. $nb = "</i></font></td>";
  36.  
  37. &get_fields;
  38.  
  39. if ($fld{'cancel'}) { 
  40.     $message = "DHCP configuration cancelled"; 
  41. } elsif ($fld{'accept'}) {
  42.     &configure;
  43.     $done = 1;
  44.     &generic;
  45.     exit 0;
  46. } elsif ($fld{'left.x'}) {
  47.     $go = "/tasks/Tasks.dhcp-start.cgi?e";
  48.     print "Content-type: text/html\n\n";
  49.     print "<HTML><HEAD>";
  50.     print "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL=$go\">";
  51.     print "</HEAD><BODY></BODY></HTML>";
  52.     exit 0;
  53. }
  54.  
  55. &readValues;
  56.  
  57. &generic;
  58.  
  59. sub getLeases {
  60.     undef @lst;
  61.     opendir(CONFIG, $def_config_dir) ||
  62.         &error("Unable to open directory $def_config_dir");
  63.     while ($name = readdir(CONFIG) ) {
  64.     if ($name =~ /^config\./) {
  65.         $ipa = $name;
  66.         $ipa =~ s/^config\.//;
  67.         if ($ipa ne "Default") { push(@lst,$ipa); }
  68.     }
  69.     }
  70.     closedir(CONFIG);
  71. }
  72.  
  73. sub configure {
  74.     &readValues;
  75.     
  76.     if ($terms{'status'} eq "Yes") {
  77.         &getLeases;
  78.  
  79.         $oldFile = $def_config_dir . "/config.Default";
  80.     
  81.         @leases = split(/&&/,$terms{'leases'});
  82.         foreach (@leases) {
  83.             $newFile = $def_config_dir . "/config." . $_;  
  84.             if (-e $newFile) { next; }
  85.         system("/sbin/cp", $oldFile, $newFile);
  86.         }
  87.  
  88.         foreach $arg (@lst) {
  89.             if (! grep(/$arg/,@leases)) {
  90.                 $newFile = $def_config_dir . "/config." . $arg;
  91.         unlink $newFile;
  92.             }
  93.         }
  94.     }
  95.    
  96.     system("/etc/chkconfig", "proclaim_server", "on"); 
  97.     &inetd_comment($terms{'status'});
  98. }
  99.  
  100. sub readValues {
  101.     open(IN,"< $temp");
  102.     while(<IN>) {
  103.         @items = split(/=/);
  104.         chop $items[1];
  105.         $terms{$items[0]} = $items[1];
  106.     }
  107.     close(IN);
  108. }
  109.  
  110. sub inetd_comment {
  111.     if ($_[0] eq "Yes") {
  112.         $comment = "/usr/etc/bootp";
  113.         $uncomment = "/usr/etc/dhcp_bootp";
  114.         $newLine = "bootp\tdgram\tudp\twait\troot\t/usr/etc/dhcp_bootp dhcp_bootp ";
  115.         $newLine .= "-o /etc/config/dhcp_bootp.options\n";
  116.     } else {
  117.         $comment = "/usr/etc/dhcp_bootp";
  118.         $uncomment = "/usr/etc/bootp";
  119.         $newLine = "bootp\tdgram\tudp\twait\troot\t/usr/etc/bootp\tbootp\n";
  120.     }
  121.  
  122.     $rename = 0;
  123.     open(IN,"< $inetd_conf");
  124.     open(OUT,"> $dummy");
  125.     while(<IN>) { 
  126.         @items = split(/\s+/);
  127.         if ($items[0] eq "bootp") {
  128.             if ($items[5] eq $comment) {
  129.                 print OUT "# $_";
  130.                 $rename = 1;
  131.             } else { print OUT $_; }
  132.         } elsif ($items[0] eq "#bootp" || $items[1] eq "bootp") {
  133.             if ($items[5] eq $uncomment || $items[6] eq $uncomment) {
  134.                 print OUT $newLine;
  135.                 $rename = 1;
  136.             } else { print OUT $_; }
  137.         } else { print OUT $_; }
  138.     }
  139.     close(IN);
  140.     close(OUT);
  141.     if ($rename) { 
  142.     rename($dummy, $inetd_conf);
  143.     system("/etc/killall", "-HUP", "inetd");
  144.     }
  145. }
  146.             
  147. sub generic {
  148.     print "Content-type: text/html\n\n";
  149.     print "<html><head><title>Summary</title>\n";
  150.         print "<script language=\"JavaScript\">\n<!--\n";
  151.  
  152.     # JavaScript
  153. print "which = \"none\";
  154. function runSubmit() {
  155.     if(which == \"accept\") return (true);
  156.     if(which == \"cancel\") return runCancel();
  157.     return (true);
  158. }   
  159. function markAccept() { which = \"accept\"; }
  160. function markCancel() { which = \"cancel\"; }
  161. function runCancel()  {
  162.     setTimeout('window.location=\"/tasks/Tasks.dhcp-start.cgi?end\"',0);
  163.     return (false);
  164. }
  165. function Previous()  {
  166.     setTimeout('window.location=\"/tasks/Tasks.dhcp-start.cgi?end\"',0);
  167.     return;
  168. }\n";
  169.  
  170.     print "//-->\n";
  171.     print "</script></head>\n\n";
  172.  
  173.  
  174.     print "<body bgcolor='ddc4b2' background=/tasks/dhcp-task.bg.gif>\n";
  175.  
  176.     print "<i>$message</i>";
  177.  
  178.     print "<table width=100%>",
  179.           "<tr><th align=left><h1>Summary</h1></th>\n",
  180.           "<th align=right><a href=\"/newsplash.shtml\">",
  181.           "<img height=55 width=57 border=0 src=/tasks/home.gif></a>\n",
  182.           "  <a href=\"/tasks/Tasks.shtml\">",
  183.           "<img height=55 width=57 border=0 src=/tasks/back.gif></a>",
  184.           "</tr></table>\n";
  185.  
  186.     if ($done) {        
  187.         print qq|<center><br><br><br><br><font size=5>\n|;
  188.         print qq|<i>Your DHCP server has been configured.</i>\n|;
  189.         print qq|</font></center></body></html>\n|;
  190.         return 0;
  191.     }
  192.  
  193. print "<br>
  194. Review the information that you entered in the DHCP configuration
  195. form:<br><br>\n\n";
  196.  
  197.     print "<center><table width=300>\n";
  198.  
  199.     print "<tr><td>Enable DCHP server: </td><td><tt>$terms{'status'}</tt></td></tr>\n";
  200.     if ($terms{'status'} eq 'Yes') {
  201.     print "<tr><td>Subnets served: </td><td><tt>";
  202.     $terms{'leases'} =~ s/&&/<br>/g;
  203.     print $terms{'leases'},"</tt></td></tr>";
  204.     }
  205.  
  206.     print "</table></center><br>\n\n";
  207.  
  208.     printf("<form name=\"end\" action=\"%s\" method=post onSubmit=\"return runSubmit()\">\n", $myname);
  209.  
  210. print "<center><table width=630><tr><td width=50%>",
  211.     "    If the information above is correct, select <I>Accept</I> to
  212.     configure the Internet Gateway as a DHCP server.</td>";
  213.  
  214.     print "<td align=right><font size=5><i>\n";
  215.     print qq|<input type=submit name="accept" value="Accept"
  216.     onClick="markAccept()">\n|;
  217.     print "</i></font></td></tr>\n\n";
  218.  
  219. print "<tr><td>",
  220.     "    If you see an error in the information above, select <I>Cancel</I> to 
  221.     delay the configuration and return to the DHCP configuration form 
  222.     to correct your entries.</td>";
  223.  
  224.     print "<td align=right><font size=5><i>\n";
  225.     print qq|<input type=submit name="cancel" value="Cancel"
  226.     onClick="markCancel()">\n|;
  227.     print "</i></font></td></tr></table></center><br>\n\n";
  228.  
  229.     print '<MAP NAME="js_map1">',
  230.     '    <AREA SHAPE="rect" COORDS="0,0,59,52" HREF="javascript:Previous()">',
  231.     '</MAP>',
  232.     '<IMG SRC="/tasks/leftarrow.gif" BORDER=0 USEMAP="#js_map1" ALIGN="right">';
  233.  
  234.     print "\n</form></body></html>";
  235. }
  236.